<template>
	<view>
			<view style="margin: 10rpx;display: flex;align-items: center;justify-content: space-between;">
				<view class="">
					<u--input
					   placeholder="请输入用户id"
					   border="surround"
					   v-model="addUserId"
					   style="width: 600rpx;"
					 ></u--input>
				</view>
				 <view class="" @click="searchFriend">
				 	<u-button text="搜索" color="#2BDC70"></u-button>
				 </view>
			</view>
			<view class="" style="margin:15rpx">
				搜索结果
			</view>
			
			<u-cell
				:title="searchUser.account"
				v-show="searchUser.account"
			>
				<view class="" slot="icon" style="padding-right: 20rpx;">
				
					<u-avatar   shape="square" :src="searchUser.picture||'???'" ></u-avatar>
				</view>
				<view slot="value" v-if="searchUser.is_friend!=1">
						<u-button text="添加" color="#2BDC70" v-if="searchUser.is_friend==0" @click="addFriend(searchUser.id)"></u-button>
						<view v-else>已申请</view>
				</view>
			</u-cell>
			
			
			<view style="margin:15rpx">通知列表</view>
			
			<u-list
					
					>
						<u-list-item
							v-for="(item, index) in noticeList"
							:key="index"
						>
							<u-cell
								:title="item.account"
							>
								<view class="" slot="icon" style="padding-right: 20rpx;">
									<u-avatar   shape="square" :src="item.picture"></u-avatar>
								</view>
								<view slot="value">
									
									<view v-if="item.status==0" style="display: flex;">
										<u-button text="同意" color="#2BDC70" @click="audit(item,1)"></u-button>
										<u-button text="拒绝" color="#A8ABA9" @click="audit(item,2)"></u-button>
									</view>
									<view v-if="item.status==1">
										已同意
									</view>
									<view v-if="item.status==2">
										未同意
									</view>
								</view>
							</u-cell>
						</u-list-item>
					</u-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addUserId:'',
				noticeList:[],
				searchUser:{}
			}
		},
		onLoad() {
			this.getNoticeList()
		},
		methods: {
			getNoticeList(){
				this.$myRquest({
					url:'/friend/get_apply',
					method:"get"	
				}).then(res=>{
					this.noticeList=res.data.data.list.reverse()
					console.log(this.noticeList)
				})
			},
				
			searchFriend(){
				this.$myRquest({
					url:'/user/list',
					method:'get',
					data:{
						user_id:this.addUserId
					}
					
				}).then(res=>{
					console.log(res)
					this.$nextTick(function(){
						this.searchUser=res.data.data.list[0]||{}
					})
				})
			},
			audit(user,status){
			
				this.$myRquest({
					url:'/friend/pass_or_notpass',
					method:'post',
					data:{
						apply_id:user.apply_id,
						status
					}
				}).then(res=>{
					this.getNoticeList()
				})
			},
			addFriend(){
				this.$myRquest({
					url:'/friend/add_friend',
					method:"post",
					data:{
						other_user_id:this.addUserId
					}
				}).then(res=>{
					
					console.log(this.noticeList)
					this.searchUser.is_friend='已申请'
				})
			}
		}
	}
</script>

<style>

</style>
